/* ----------------------------------------------------------------------------
* File: module_talk_impl.h
*
* Desc: Talk module implementation
*
* Created: 21/05/2011, by Alexey Korshunov
* ---------------------------------------------------------------------------- */
#ifndef _MODULE_TALK_IMPL_H_
#define _MODULE_TALK_IMPL_H_

#include "module_talk.h"
#include "exception.h"

#include <atlbase.h>
#include <atlcom.h>


namespace ModuleManagement
{
	class TalkModuleImpl : public TalkModule
	{
		friend void CallbackNewInputData(void* param);
	public:
		TalkModuleImpl();
		~TalkModuleImpl();

		void Init(const TalkModuleParams& params) throw(Common::Exception);

		// TalkModule implementation
		virtual Common::Error Start(void* param = NULL, size_t size = 0);
		virtual Common::Error Stop(void* param = NULL, size_t size = 0);

	private:
		static DWORD WINAPI ThreadFunc(LPVOID param);
		void CreateSyncObjects() throw(Common::Exception);
		void DestroySyncObjects();
		void StopThread();
		int AILogic(const std::string& InputMsg, std::string& OutputMsg);

		Common::MessageQueue* InputQueue;
		Common::MessageQueue* OutputQueue;
		HANDLE Thread;
		HANDLE StartEvent;
		HANDLE NewDataEvent;
		HANDLE StopEvent;
	};
}

#endif // _MODULE_TALK_IMPL_H_


